/*
 ============================================================================
 Name        : download.c
 Author      : chenf
 Version     :
 Copyright   : loongsec
 Description : Start or Stop LS_, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cgi.h"
#include "cookie.h"
#include "stdx.h"

int main(void) {
    FILE * fp = NULL;
    int c = 0;

    if(isvalid_cookie() != 0){
        return 0;
    }

    fp = fopen("/home/loongsec/database/database.db", "rb");
    printf("Content-Disposition:attachment;filename=database;");
    printf("Content-type:application/octet-stream\n\n");
    
    if(fp!=NULL){
        int size = 0;
        c = getc(fp);
        while(!feof(fp)){
            //printf("%d, ", size);
            putc(c, stdout);
            c = getc(fp);
        }       
        fclose(fp);
    } else {
        printf("file open faild.\n");
    }
    
    return 0;
}

